/**============================================================================
 Confidential Information - Limited distribution to authorized persons only.
 This software is protected as an unpublished work under the U.S. Copyright
 Act of 1976.

 Copyright (c) 2011, BluePhoenix Solutions, Inc. All rights reserved.
 ----------------------------------------------------------------------------
 file......: PredCoreStringUtilsTest.java
 Author....: Vyacheslav Kovalyov
 Created...: 28.10.11

 Description:

 ============================================================================*/
package ru.monyag.pred.core.utils;

import org.junit.Test;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.apache.commons.lang.StringUtils.EMPTY;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.springframework.util.CollectionUtils.arrayToList;
import static ru.monyag.pred.core.utils.PredCoreConstants.TAGS_SEPARATOR;
import static ru.monyag.pred.core.utils.PredCoreStringUtils.parseTags;

/**
 * @author Vyacheslav Kovalyov
 * @version 1.0
 */
public class PredCoreStringUtilsTest {

    private static final String TAGS = "tag1, tag2   , tag3,,tag4,,,";
    private static final String CORRECT_TAGS = "tag1, tag2, tag3, tag4";
    private static final String[] CORRECT_TAGS_LIST = new String[]{"tag1", "tag2", "tag3", "tag4"};

    private static final String EMPTY_TAGS = EMPTY;
    private static final String NULL_TAGS = null;
    private static final String SPACES_ONLY_TAGS = "           ";
    private static final String SEPARATORS_ONLY_TAGS = TAGS_SEPARATOR + "   " + TAGS_SEPARATOR + TAGS_SEPARATOR;

    @Test
    public void shouldParseString() throws Exception {
        List<String> parsedTags = parseTags(TAGS);

        assertThat(parsedTags.size() == CORRECT_TAGS_LIST.length, is(true));

        for (int i = 0; i < CORRECT_TAGS_LIST.length; i++) {
            assertThat(parsedTags.get(i).equals(CORRECT_TAGS_LIST[i]), is(true));
        }
    }

    @Test
    public void shouldReturnEmptyList() throws Exception {
        assertThat(CollectionUtils.isEmpty(parseTags(EMPTY_TAGS)), is(true));
        assertThat(CollectionUtils.isEmpty(parseTags(NULL_TAGS)), is(true));
        assertThat(CollectionUtils.isEmpty(parseTags(SPACES_ONLY_TAGS)), is(true));
        assertThat(CollectionUtils.isEmpty(parseTags(SEPARATORS_ONLY_TAGS)), is(true));
    }

    @Test
    @SuppressWarnings("unchecked")
    public void shouldCreateCorrectTags() throws Exception {
        String tags = parseTags(arrayToList(CORRECT_TAGS_LIST));
        assertThat(tags.equals(CORRECT_TAGS), is(true));
    }
}
